package com.jinxin.phonecloudmusic.myapplication.fragment.fra;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jinxin.phonecloudmusic.myapplication.R;
import com.jinxin.phonecloudmusic.myapplication.app.JxscApp;
import com.jinxin.phonecloudmusic.myapplication.base.BaseFragment;
import com.jinxin.phonecloudmusic.myapplication.entity.GroupBean.Play;
import com.jinxin.phonecloudmusic.myapplication.event.MusicControlEvent;
import com.jinxin.phonecloudmusic.myapplication.utils.RxBus;
import com.squareup.picasso.Picasso;

import butterknife.BindView;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;

/**
 * Created by ZJ on 2017/10/9 0009.
 */

public class PlayMusicSongsFragment extends BaseFragment{
    @BindView(R.id.iv_songer)
    ImageView ivSonger;
    @BindView(R.id.tv_songer)
    TextView tvSonger;
    @BindView(R.id.iv_album)
    ImageView ivAlbum;
    @BindView(R.id.tv_album)
    TextView tvAlbum;

    private Play play;
    @Override
    public View inflate(LayoutInflater inflater, ViewGroup container) {
        return inflater.inflate(R.layout.fra_music_songer, container, false);
    }

    @Override
    public void initData() {
        RxBus.getDefault().register(MusicControlEvent.class).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<MusicControlEvent>() {
            @Override
            public void accept(MusicControlEvent event) throws Exception {
                if ((event.getTag()) == 9) {//上下首
                    play=(Play)(event.getObj1());
                    if (null!=tvSonger)
                    tvSonger.setText(play.getSongInfo().getAuthor());
                    if (null!=tvAlbum)
                    tvAlbum.setText(play.getSongInfo().getAlbum_title());
                    if (null!=ivSonger)
                    Picasso.with(JxscApp.getContext()).load(play.getSongInfo().getPic_small()).placeholder(R.drawable.background).error(R.drawable.background).into(ivSonger);
                    if (null!=ivAlbum)
                    Picasso.with(JxscApp.getContext()).load(play.getSongInfo().getPic_small()).placeholder(R.drawable.background).error(R.drawable.background).into(ivAlbum);
                }
            }
        });
    }
}
